<?php
include_once("adminBase.php");

class Manager extends AdminBase{
	function index()
	{
		global $permissionGrade;
		$sql = "select * from tbl_manager";
		$this->db->setQuery($sql);
		$rows = $this->db->loadList();
		foreach($rows as $key=>$value)
		{
			$rows[$key]['grade'] = $permissionGrade[$value['grade']];
			$rows[$key]['status'] = $value['status'] == '0'?'正常':'已注销 <a style="color:red" href="javascript:void(0);" onclick="active(\''.$value['id'].'\')">激活</a>';
		}
		$this->smarty->assign("rows",$rows);
		adminDisplay("admin_manager.tpl");
	}
	
	function del()
	{
		$id = intval($_REQUEST['id']);
		$sql = "update tbl_manager set status='1' where id='$id'";
		$this->db->query($sql);
		$this->index();
	}
	
	function active()
	{
		$id = intval($_REQUEST['id']);
		$sql = "update tbl_manager set status='0' where id='$id'";
		$this->db->query($sql);
		$this->index();
	}
	
	function add()
	{
		global $permissionGrade;
		if(isset($_REQUEST['id']) && $_REQUEST['id'] >0){
			$id = $_REQUEST['id'];
			$sql = "select * from tbl_manager where id='$id'";
			$row = $this->db->loadRow($sql);
			$this->smarty->assign("row",$row);
		}
		$this->smarty->assign("permissionGrade",$permissionGrade);
		adminDisplay("admin_manager_add.tpl");
	}
	
	function save()
	{
		$tempRow['user_id'] = trim($_REQUEST['user_id']);
		$tempRow['user_name'] = trim($_REQUEST['user_name']);
		if(!empty($_REQUEST['password'])){
			$tempRow['password'] = md5(trim($_REQUEST['password']));
		}
		$tempRow['grade'] = intval($_REQUEST['grade']);
		$tempRow['status'] = '0';
		$id = intval($_REQUEST['id']);
		if($id > 0){
			$where = " where id='$id'";
			$this->db->update($tempRow, 'tbl_manager', $where);
		}else{
			$this->db->insert($tempRow, 'tbl_manager');
		}
		$this->index();
	}

}
$manager = new Manager('tbl_manager');